package com.singzi.leetcode.N200;

public class T0152 {
    public static void main(String[] args) {
        int []nums = {2,3,-2,4};
        Solution0152 solution0152 = new Solution0152();
        System.out.println(solution0152.maxProduct(nums));
    }
}
class Solution0152 {
    public int maxProduct(int[] nums) {
        int max = nums[0],min = nums[0],ans = nums[0];
        for(int i = 1;i < nums.length;i++){
            int maxTemp = max, minTemp = min;
            max = Math.max(nums[i], Math.max(maxTemp*nums[i], minTemp*nums[i]));
            min = Math.min(nums[i], Math.min(maxTemp*nums[i], minTemp*nums[i]));
            ans = Math.max(max, ans);
        }
        return ans;

    }
}
